    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package entity;

    import java.io.Serializable;
    import java.util.Date;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.PrePersist;
    import javax.persistence.PreUpdate;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
    import javax.validation.constraints.NotNull;
    import javax.validation.constraints.Size;
    import javax.xml.bind.annotation.XmlRootElement;

    /**
     *
     * @author Wink
     */
    @Entity
    @Table(name = "posts")
    @XmlRootElement
    @NamedQueries({@NamedQuery(name = "Post.find", query = "SELECT p FROM Post p WHERE "
            + "p.boardId = :board_id AND p.timestamp BETWEEN :from_when AND :to_when")})
    //    @NamedQuery(name = "Posts.findAll", query = "SELECT p FROM Posts p"),
    //    @NamedQuery(name = "Posts.findById", query = "SELECT p FROM Posts p WHERE p.id = :id"),
    //    @NamedQuery(name = "Posts.findByBoardId", query = "SELECT p FROM Posts p WHERE p.boardId = :boardId"),
    //    @NamedQuery(name = "Posts.findByText", query = "SELECT p FROM Posts p WHERE p.text = :text"),
    //    @NamedQuery(name = "Posts.findByUserName", query = "SELECT p FROM Posts p WHERE p.userName = :userName"),
    //    @NamedQuery(name = "Posts.findByTimestamp", query = "SELECT p FROM Posts p WHERE p.timestamp = :timestamp"),
    //    @NamedQuery(name = "Posts.findByLat", query = "SELECT p FROM Posts p WHERE p.lat = :lat"),
    //    @NamedQuery(name = "Posts.findByLng", query = "SELECT p FROM Posts p WHERE p.lng = :lng")})
    public class Post implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "id")
        private Long id;
        @NotNull
        @Column(name = "board_id")
        private long boardId;
        @NotNull
        @Size(min = 1, max = 1000)
        @Column(name = "text")
        private String text;
        @NotNull
        @Size(min = 1, max = 20)
        @Column(name = "user_name")
        private String userName;
        @Column(name = "timestamp")
        @Temporal(TemporalType.TIMESTAMP)
        private Date timestamp;
        @Column(name = "lat")
        private double lat;
        @Column(name = "lng")
        private double lng;

        @PrePersist 
        protected void onCreate() {
            timestamp = new Date();
        }

        @PreUpdate 
        protected void onUpdate() {
            timestamp = new Date();
        }

        public Post() {
        }

        public Post(long boardId, String text, String userName,
                double lat, double lng) {
            this.boardId = boardId;
            this.text = text;
            this.userName = userName;
            this.lat = lat;
            this.lng = lng;
        }

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public long getBoardId() {
            return boardId;
        }

        public void setBoardId(long boardId) {
            this.boardId = boardId;
        }

        public String getText() {
            return text;
        }

        public void setText(String text) {
            this.text = text;
        }

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }

        public Date getTimestamp() {
            return timestamp;
        }

        public void setTimestamp(Date timestamp) {
            this.timestamp = timestamp;
        }

        public double getLat() {
            return lat;
        }

        public void setLat(double lat) {
            this.lat = lat;
        }

        public double getLng() {
            return lng;
        }

        public void setLng(double lng) {
            this.lng = lng;
        }
    }
